//
//  NewTuiGuangViewController.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/29.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "NewTuiGuangViewController.h"
#import "JTCSM.h"
#import "NewTuiGuangTableViewCell.h"
#import "ImageBtn.h"
#import "NewTuiGuangInfoViewController.h"

@interface NewTuiGuangViewController ()<UITableViewDelegate,UITableViewDataSource>
{
    UITableView *_tableview;
    UIImageView *headerImageV;
}

@end

@implementation NewTuiGuangViewController

- (void)gotBack{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [df isRemoveTarbar:YES];
    self.navigationController.navigationBar.hidden = NO;
    self.view.backgroundColor =[UIColor whiteColor];
    leftBarButtonItems_rightBarButtonItems *leftbtn = KCUSTOMNAVIGSTION_ALLOC;
    self.navigationItem.leftBarButtonItem = [leftbtn setBarButtonItemsImageName:@"fanhui.png" frame:KLeftBarButtonItemFrame_image target:self SEL:@selector(gotBack)];
    // Do any additional setup after loading the view.
    [self layoutTableView];
}

- (void)layoutTableView{
    
    _tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERHeight) style:UITableViewStylePlain];
    _tableview.delegate = self;
    _tableview.dataSource = self;
    _tableview.tableHeaderView = [self headerView];
    [self.view addSubview:_tableview];
    _tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self setUpTableView];
    //    view.backgroundColor = RGBACOLOR(241, 241, 241, 1);
}

- (UIView *)headerView{
    headerImageV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, KCONTROLLERWith*0.453333)];
    headerImageV.image = [UIImage imageNamed:@"banner1.png"];
    return headerImageV;
}

- (void)setUpTableView{
    // 1.下拉刷新(进入刷新状态就会调用self的headerRereshing)
    [_tableview addHeaderWithTarget:self action:@selector(headerRereshing)];
    
    // 上拉加载
    [_tableview addFooterWithTarget:self action:@selector(footerRereshing)];
    
}
- (void)headerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self theRequestWithKeyWord:mykeyword];
    });
}
- (void)footerRereshing{
    // 2秒后刷新表格UI
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(KRefreshTime * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //getMarriageSeeking(网络请求)
        //        [self loadMoreDataRequestWithKeyWord:mykeyword];
        
    });
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
   
    return 1;
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NSString *cellid = [NSString stringWithFormat:@"textfield%ld",(long)indexPath.row];
    NewTuiGuangTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
    if (cell == nil) {
        cell = [[NewTuiGuangTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellid];
    }
    [cell setValueWithModel:@"情人节.png"];
    return cell;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return [NewTuiGuangTableViewCell whc_CellHeightForIndexPath:indexPath tableView:tableView];

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    NewTuiGuangInfoViewController *vc = [[NewTuiGuangInfoViewController alloc]init];
    vc.nameTitle = @"节日模版";
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 50;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    switch (section) {
        case 0:
            return [self layoutHeaderViewWithTitle:@"节日模版" tag:section];
            break;
        case 1:
            return [self layoutHeaderViewWithTitle:@"风景模版" tag:section];
            break;
        default:
            
            break;
    }
    return nil;
}
- (UIView *)layoutHeaderViewWithTitle:(NSString *)title tag:(NSInteger)index{
    
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, KCONTROLLERWith, 50)];
    view.backgroundColor = [UIColor whiteColor];
    UIImageView *headerImageV = [[UIImageView alloc]initWithFrame:CGRectMake(35, 20, 5, 10)];
    headerImageV.backgroundColor = KZhuTiRGB;
    [view addSubview:headerImageV];
    
    UILabel *titleLabel = [UILabel initWithFrame:CGRectMake(KVIEW_X(headerImageV)+10, 15, KCONTROLLERWith, 20) text:title font:13 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"333333" alpha:1] backgroundColor:nil];
    [view addSubview:titleLabel];
    
    CGFloat imagesize = 20;
    CGRect rect = [df labelHeightWithContent:@"更多" width:100 font:14.0];
    ImageBtn *btn = [[ImageBtn alloc] initWithFrame:CGRectMake(KCONTROLLERWith-imagesize-rect.size.width-30,3, imagesize+10+rect.size.width, 44)];
    [btn resetdata:@"更多" :[UIImage imageNamed:@"myFanhui.png"]];
    btn.tag = 200+index;
    [btn addTarget:self action:@selector(gotoMoreWith:) forControlEvents:UIControlEventTouchUpInside];
    [view addSubview:btn];
    
    return view;
}
- (void)gotoMoreWith:(UIButton *)sender{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
